﻿using ArtMath.Component;
using ArtMath.Core.Data;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.ComponentModel.Design.Serialization;
using System.Globalization;
using System.Linq;
using System.Text;

namespace ArtMath.Converter
{
    [Serializable]
    public class IntelliPointConverter : TypeConverter
    {
        public override bool CanConvertTo(ITypeDescriptorContext context, Type destinationType)
        {
            if (destinationType == typeof(string) || destinationType == typeof(InstanceDescriptor)) return true;
            return base.CanConvertTo(context, destinationType);
        }
        public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType)
        {
            if (context?.Instance != null && value is PointD)
            {
                Base obj = context.Instance as Base;
                if (obj != null)
                {
                    if (destinationType == typeof(string))
                    {
                        return obj.Pad.ShowPoint((PointD)value).ToString();
                    }
                }
            }
            return base.ConvertTo(context, culture, value, destinationType);
        }
    }
}
